package com.game.framework.message.stream;

import com.game.framework.message.event.IGameMessage;

/**
 * 网关与内部服务之间交互的消息，一般用于一请一答的交互方式，即有请求必有回应的方式。
 */
public abstract class AbstractServiceGameMessage extends AbstractGameMessage {
	private ServiceMessageHeader header;

	@Override
	protected IMessageHeader createHeader() {
		header = new ServiceMessageHeader();
		return header;
	}

	public <T extends IGameMessage> T newCouple() {
		@SuppressWarnings("unchecked")
		T t = (T) this.newCoupleImpl();
		ServiceMessageHeader coupleHeader = (ServiceMessageHeader) t.getHeader();
		coupleHeader.setFromGameServerId(header.getToGameServerId());
		coupleHeader.setToGameServerId(header.getFromGameServerId());
		coupleHeader.setMessageSeqId(header.getMessageSeqId());
		coupleHeader.setUserId(header.getUserId());
		return t;
	}

	protected abstract IGameMessage newCoupleImpl();
	
	
}
